package com.example.mybatisstudy.controller;

import com.example.mybatisstudy.mapper.ArticleMapper;
import com.example.mybatisstudy.model.Articleinfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/article")
public class ArticleController {

    private static final Map map = new HashMap<>();

    @Autowired
    private ArticleMapper articleMapper;

    @RequestMapping("/queryAll")
    public Object queryAll(){
        return articleMapper.all();
    }

    @RequestMapping("/query")
    public Object query(Integer id){
        return articleMapper.queryById(id);
    }

    @RequestMapping("/add")
    public Object add(Articleinfo a){
        int num = articleMapper.add(a);
        return map;
    }

    @RequestMapping("/modify")
    public Object modify(Articleinfo a){
        int num = articleMapper.modify(a);
        return map;
    }

    @RequestMapping("/del")
    public Object del(Integer id){
        return articleMapper.del(id);
    }

    @RequestMapping("/sort")
    public Object sort(String col, String sortBy){
        Map<String, String> map = new HashMap<>();
        map.put("col", col);
        map.put("sortBy", sortBy);
        return articleMapper.querySort(map);
    }

    @RequestMapping("/sort2")
    public Object sort2(String col, String sortBy){
        return articleMapper.querySort2(col, sortBy);
    }

    @RequestMapping("/queryByTitle")
    public Object queryByTitle(String title){
        return articleMapper.queryByTitle(title);
    }

    @RequestMapping("/queryLikeTitle")
    public Object queryLikeTitle(String title){
        return articleMapper.queryLikeTitle(title);
    }

    @RequestMapping("/queryArticleWithUser")
    public Object queryArticleWithUser(){
        return articleMapper.queryArticleWithUser();
    }
}
